*** Barberia et al. (2022)
*** Brazilian Political Science Review
*** "The Relationship between Ideology and COVID-19 Deaths: What We Know and What We Still Need to Know"
*** Figure 12

clear
cd "/Users/nataliamoreira/Dropbox/Replication BPSR"

use "Data/voteshare_covidcasesdeaths.dta", clear

* Data management 

merge m:1 códigoibge using "Data/pibpercapita"
drop _merge

* GDP per capita identifying the poorest and the richest municipalities

sum ProdutoInterno, de
* Percentile 25%: Prod <= 10527.25
* Percentile 75%: Prod >= 30031.47
	
	
* Creating a new data set in which we save the coefficient estimate from the 
* regression of votes on COVID-19 cases and deaths over time for the poorest and the richest municipalities


* 1st round

capture postutil clear
tempname regbolsopib_1st
postfile `regbolsopib_1st' week b_mortes_bolsonarovotos_p se_mortes_bolsonarovotos_p /*
*/ b_mortes_bolsonarovotos_r se_mortes_bolsonarovotos_r using "Data/mun_bolsonaro1stpib", replace

foreach i in 202014 202018 202023 202027 202031 202036 202040 202043 202049 202053 /*
	*/ 202105 202109 202113 202117 202122 {
	
	use "Data/mun_cases_deaths_bolsonaro1st", clear
	xtset códigoibge data, delta(7)
	
	keep if epidemiological_week == `i'
	scalar week = `i'
	
	encode uf, g(state)
	
	reg mortes_100k bolsonarovotos if Prod <= 10527.25
	scalar b_mortes_bolsonarovotos_p = _b[bolsonarovotos]
	scalar se_mortes_bolsonarovotos_p = _se[bolsonarovotos]
	
	reg mortes_100k bolsonarovotos if Prod >= 30031.47
	scalar b_mortes_bolsonarovotos_r = _b[bolsonarovotos]
	scalar se_mortes_bolsonarovotos_r = _se[bolsonarovotos]
				
	post `regbolsopib_1st' (week) (b_mortes_bolsonarovotos_p) (se_mortes_bolsonarovotos_p) /*
	*/ (b_mortes_bolsonarovotos_r) (se_mortes_bolsonarovotos_r) 
	} 
postclose `regbolsopib_1st'	


* Figure 12

use "Data/mun_bolsonaro1stpib.dta", clear

* 95% CI Deaths - Poorest Municipalities
g l_mortes_bolsonarovotos_p = b_mortes_bolsonarovotos_p - (1.96*se_mortes_bolsonarovotos_p)
g h_mortes_bolsonarovotos_p = b_mortes_bolsonarovotos_p + (1.96*se_mortes_bolsonarovotos_p)

* 95% CI Deaths - Richest Municipalities
g l_mortes_bolsonarovotos_r = b_mortes_bolsonarovotos_r - (1.96*se_mortes_bolsonarovotos_r)
g h_mortes_bolsonarovotos_r = b_mortes_bolsonarovotos_r + (1.96*se_mortes_bolsonarovotos_r)

g t = _n
label define datel 1 "2020-03-31" 2 "2020-04-30" 3 "2020-05-31" 4 "2020-06-30" 5 "2020-07-31" /*
*/ 6 "2020-08-31" 7 "2020-09-30" 8 "2020-10-24" 9 "2020-11-30" 10 "2020-12-31" /*
*/ 11 "2021-01-31" 12 "2021-02-28" 13 "2021-03-31" 14 "2021-04-30" 15 "2021-05-31"
label values t datel 
label variable t "month"

* The effect of Bolsonaro vote share on cases per 100,000

* Figure 12. Panel A. 1st wave

twoway rcap h_mortes_bolsonarovotos_p l_mortes_bolsonarovotos_p t if t<9, /*
	*/ lcolor(black) lwi(thick) yline(0, lcolor(red) lpattern(dash)) msize(vsmall) ||  /*
	*/ rcap h_mortes_bolsonarovotos_r l_mortes_bolsonarovotos_r t if t<9, /*
	*/ lcolor(black*0.3) lwi(thick) yline(0, lcolor(red) lpattern(dash)) msize(vsmall) /*
	*/ xlabel(1(1)8,labs(small) valuelabel) /*
	*/ title("", size(medium)) xtitle("") /*
	*/ ylabel(,labs(vsmall) nogrid) /*
	*/ legend(off) ytitle("Estimated effect") || /*
	*/ scatter b_mortes_bolsonarovotos_p t if t<9, msymbol(O) mcolor(black) msize(medlarge) || /*
	*/ scatter b_mortes_bolsonarovotos_r t if t<9, msymbol(O) mcolor(black*0.3) msize(medlarge) 

graph export "Figures/figure12_panela.png", replace
	
* Figure 12. Panel B. 2nd wave

twoway rcap h_mortes_bolsonarovotos_p l_mortes_bolsonarovotos_p t if t>8, /*
	*/ lcolor(black) lwi(thick) yline(0, lcolor(red) lpattern(dash)) msize(vsmall) ||  /*
	*/ rcap h_mortes_bolsonarovotos_r l_mortes_bolsonarovotos_r t if t>8, /*
	*/ lcolor(black*0.3) lwi(thick) yline(0, lcolor(red) lpattern(dash)) msize(vsmall) /*
	*/ xlabel(9(1)15,labs(small) valuelabel) /*
	*/ title("", size(medium)) xtitle("") /*
	*/ ylabel(,labs(small) nogrid) /*
	*/ legend(off) ytitle("Estimated effect") || /*
	*/ scatter b_mortes_bolsonarovotos_p t if t>8, msymbol(O) mcolor(black) msize(medlarge) || /*
	*/ scatter b_mortes_bolsonarovotos_r t if t>8, msymbol(O) mcolor(black*0.3) msize(medlarge) 
	
graph export "Figures/figure12_panelb.png", replace
	
